<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<h2>SCM Information</h2>
<table class="table table-bordered table-striped">
    <tbody>
    <tr>
        <td>Scm Id:</td>
        <td>{{$ctrl.overview.jmx.ScmId}}</td>
    </tr>
    <tr>
        <td>Cluster Id:</td>
        <td>{{$ctrl.overview.jmx.ClusterId}}</td>
    </tr>
    </tbody>
</table>

<h2>Node Status</h2>
<div class="row">
    <div class="col-md-6 text-left">
        <label>Show: </label>
        <select class="form-select" ng-model="RecordsToDisplay" ng-change="UpdateRecordsToShow()">
            <option value="10" ng-selected="{true}">10</option>
            <option value="20">20</option>
            <option value="50">50</option>
            <option value="All">All</option>
        </select>
    </div>
    <div class="col-md-6 text-right">
        <label>Search: </label> <input type="text" ng-model="search">
    </div>
</div>
<table class="table table-bordered table-striped col-md-6">
    <thead>
        <tr>
            <th ng-click = "columnSort('hostname')" class="nodeStausInfo"><span ng-class = "{'sorting' : (columnName != 'hostname'), 'sortasc' : (columnName == 'hostname' && !reverse),
                                        'sortdesc':(columnName == 'hostname' && !reverse)}">HostName</span></th>
            <th ng-click = "columnSort('opstate')" class="nodeStausInfo" ><span ng-class="{'sorting' : (columnName != 'opstate'), 'sortasc' : (columnName == 'opstate' && !reverse),
                                        'sortdesc':(columnName == 'opstate' && !reverse)}">Operational State</span></th>
            <th ng-click = "columnSort('comstate')" class="nodeStausInfo">  <span ng-class="{'sorting' : (columnName != 'comstate'), 'sortasc' : (columnName == 'comstate' && !reverse),
                                        'sortdesc':(columnName == 'comstate' && !reverse)}">Commisioned State</span> </th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="typestat in nodeStatus|filter:search|orderBy:columnName:reverse">
            <td ng-switch="typestat.port > 0">
                <span ng-switch-when="true">
                    <a href="{{typestat.protocol}}://{{typestat.hostname}}:{{typestat.port}}" target="_blank">{{typestat.hostname}}</a>
                </span>
                <span ng-switch-when="false">
                    {{typestat.hostname}}
                </span>
            </td>
            <td>{{typestat.opstate}}</td>
            <td>{{typestat.comstate}}</td>
       </tr>
    </tbody>
</table>

<div class="row">
    <div class="col-md-6 text-left">
        <label>Page:</label>
        <select class="form-select" ng-model="currentPage" ng-change="handlePagination(currentPage, false)">
            <option ng-repeat="page in getPagesArray()" ng-value="page">{{page}}</option>
        </select>
        <span>of {{lastIndex}}. </span>
        <span ng-if="nodeStatus && nodeStatus.length > 0">
            Showing {{getCurrentPageFirstItemIndex()}} to {{getCurrentPageLastItemIndex()}} of the total {{totalItems}} entries.
        </span>
    </div>
    <div class="col-md-6 text-right">
        <nav aria-label="..." ng-show="RecordsToDisplay !== 'All'">
            <ul class="pagination" style="margin: 0; padding: 0">
                <li class="page-item" ng-class="{disabled:currentPage==1}"
                    ng-click="handlePagination(currentPage-1,(currentPage==1))">
                    <span class="page-link" tabindex="-1">Previous</span>
                </li>
                <li class="page-item active">
                    <span class="page-link">{{currentPage}} </span>
                </li>
                <li class="page-item" ng-class="{disabled:lastIndex==currentPage}"
                    ng-click="handlePagination(currentPage+1, (lastIndex==currentPage))">
                    <span class="page-link" tabindex="-1">Next</span>
                </li>
            </ul>
        </nav>
    </div>
</div>

<h2>Status</h2>
<table class="table table-bordered table-striped" class="col-md-6">
    <tbody>
    <tr>
        <td>Client Rpc port</td>
        <td>{{$ctrl.overview.jmx.ClientRpcPort}}</td>
    </tr>
    <tr>
        <td>Datanode Rpc port</td>
        <td>{{$ctrl.overview.jmx.DatanodeRpcPort}}</td>
    </tr>
    <tr>
        <td>Node Manager: Safe mode status</td>
        <td>{{$ctrl.overview.jmx.InSafeMode}}</td>
    </tr>
    <tr>
        <td> SCM Roles (HA) </td>
        <td>{{$ctrl.overview.jmx.ScmRatisRoles}}</td>
    </tr>
    <tr ng-hide="!$ctrl.overview.jmx.PrimordialNode">
        <td> Primordial Node (HA) </td>
        <td>{{$ctrl.overview.jmx.PrimordialNode}}</td>
    </tr>
    </tbody>
</table>

<h2>Meta-Data Volume Information</h2>
<table class="table table-bordered table-striped" class="col-md-6">
    <tbody>
    <tr>
        <td>Ratis Directory</td>
        <td>{{$ctrl.overview.jmx.RatisLogDirectory}}</td>
    </tr>
    <tr>
        <td>RocksDB Directory</td>
        <td>{{$ctrl.overview.jmx.RocksDbDirectory}}</td>
    </tr>
    </tbody>
</table>

<h2>Safemode rules statuses</h2>

<table class="table table-bordered table-striped" class="col-md-6">
    <thead>
    <tr>
        <th>Rule Id</th>
        <th>Rule definition</th>
        <th>Passed</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="typestat in $ctrl.overview.jmx.SafeModeRuleStatus">
        <td>{{typestat.key}}</td>
        <td>{{typestat.value[0]}}</td>
        <td>{{typestat.value[1]}}</td>
    </tr>
    </tbody>
</table>